package com.yunang.officialweb.controller;

import com.yunang.officialweb.common.R;
import com.yunang.officialweb.entity.ProductionDesc;
import com.yunang.officialweb.entity.TotalDesc;
import com.yunang.officialweb.service.NewsService;
import com.yunang.officialweb.service.ReProService;
import com.yunang.officialweb.service.TotalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author duan
 * @date 2022/12/1 13:21
 */
@RestController
@RequestMapping("/OfficialWebsite")
public class ReProController {
    @Autowired
    private ReProService reProService;

    @Autowired
    private TotalService totalService;

    @RequestMapping(value = "/selectViewDesc", method = RequestMethod.GET)
    public R selectViewDesc() {
        return R.ok(reProService.selectViewDesc());
    }

    @RequestMapping(value = "/updateViewDesc", method = RequestMethod.PUT)
    public R updateViewDesc(@RequestParam(required = false) String chineseName,
                            @RequestParam(required = false) String text) {
        TotalDesc totalDesc = new TotalDesc();
        totalDesc.setChineseName(chineseName);
        totalDesc.setText(text);
        return R.ok(reProService.updateViewDesc(totalDesc));
    }

    @RequestMapping(value = "/selectProductionTitle", method = RequestMethod.GET)
    public R selectProductionTitle() {
        return R.ok(reProService.selectProductionTitle());
    }

    @RequestMapping(value = "/updateProductionTitle", method = RequestMethod.PUT)
    public R updateProductionTitle(@RequestParam(required = false) String chineseName,
                                   @RequestParam(required = false) String text,
                                   @RequestParam(required = false) String desc) {
        TotalDesc totalDesc = new TotalDesc();
        totalDesc.setChineseName(chineseName);
        totalDesc.setText(text);
        totalDesc.setDesc1(desc);
        return R.ok(reProService.updateProductionTitle(totalDesc));
    }

    @RequestMapping(value = "/selectProductionDesc", method = RequestMethod.GET)
    public R selectProductionDesc() {
        return R.ok(reProService.selectProductionDesc());
    }

    @RequestMapping(value = "/updateProductionDesc", method = RequestMethod.PUT)
    public R updateProductionDesc(@RequestParam int productionId,
                                  @RequestParam(required = false) String productionName,
                                  @RequestParam(required = false) String productionText,
                                  @RequestParam(required = false) MultipartFile file) {
        ProductionDesc productionDesc = new ProductionDesc();
        productionDesc.setProductionName(productionName);
        productionDesc.setProductionText(productionText);
        productionDesc.setImgSrc(totalService.savePic(file, "D://YunAng-web//recPro//"));
        return R.ok(reProService.updateProductionDesc(productionId,productionDesc));
    }


}
